import moment from 'moment';

export const formatDate = 'YYYY-MM-DD';
export const formatSecond = 'YYYY-MM-DD HH:mm:ss';

export interface ObjectType {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  [propName: string]: any;
}

/*
 * 把获取到的时间戳转换为 年-月-日
 */
export function transferTimestamp(timestamp: number) {
  return moment(timestamp).format(formatDate);
}

/*
 * 把获取到的时间戳转换为 年-月-日 时-分-秒
 */
export function transferTimestampToSecond(timestamp: number) {
  return moment(timestamp).format(formatSecond);
}

export function mapStateToProps({ risk }: { risk: ObjectType }) {
  return { risk };
}

export function getRangePickerTime(values: ObjectType) {
  let startDate: string;
  let endDate: string;
  const range = values ? values['select-date'] : [];
  if (range.length > 0) {
    // eslint-disable-next-line no-underscore-dangle,prefer-const
    startDate = moment(range[0]._d).format(formatSecond);
    // eslint-disable-next-line no-underscore-dangle,prefer-const
    endDate = moment(range[1]._d).format(formatSecond);
  } else {
    const date = moment(Date.now()).format('YYYY-MM-DD');
    startDate = `${date} 00:00:00`;
    endDate = `${date} 23:59:59`;
  }
  return [startDate, endDate];
}
